<%@ page import="com.my.entity.User" %>
<%@ page import="java.util.List" %>
<%@ page import="com.my.entity.Page" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/8/2
  Time: 20:58
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <script type="text/javascript" src="/js/jquery-3.4.1.js"></script>
    <script type="text/javascript">
        function submitForm(){
            var form = document.getElementById("myform");
            form.submit();
        }
    </script>
    <title>分页用户列表</title>
  </head>
  <body>
    <%
        /*
        * 在分页显示的前提下：为了显示数据需要jsp有哪些数据
        *     当前页  currentPage
        *     页面大小  pageSize
        *     当前页的数据集合  users
        *     总数据  totalCount
        *     总页数  totalPage
        * */
    %>
    <table border="1px">
        <tr>
          <th>用户名</th>
          <th>密码</th>
        </tr>
        <%
            Page pages = (Page) request.getAttribute("page");
          for(User user: pages.getUsers()){
        %>
        <tr>
          <td><a href="QueryOneUserServlet?uname=<%=user.getName()%>"><%=user.getName()%></a></td>
          <td><%=user.getPwd()%></td>
        </tr>
        <%
          }
        %>
    </table>
    <br/>
    <a href="AddUser.jsp">添加用户信息</a><br/>
    <a href="deleteUser.jsp">删除用户信息</a><br/>
    <a href="updateUser.jsp">更新用户密码</a><br/>
    <a href="QueryUsersByPageServlet?currentPage=1&selPageSize=<%=pages.getPageSize()%>">首页</a>
    <a href="QueryUsersByPageServlet?currentPage=<%=pages.getCurrentPage()-1%>&selPageSize=<%=pages.getPageSize()%>">上一页</a>
    <a href="QueryUsersByPageServlet?currentPage=<%=pages.getCurrentPage()+1%>&selPageSize=<%=pages.getPageSize()%>">下一页</a>
    <a href="QueryUsersByPageServlet?currentPage=<%=pages.getTotalPage()%>&selPageSize=<%=pages.getPageSize()%>">尾页</a><br/>

    <form action="QueryUsersByPageServlet" method="post" id="myform">
        每页显示
        <select name="selPageSize" onchange="submitForm();" id="sel">
            <option value="3">3</option>
            <option value="5">5</option>
            <option value="10">10</option>
        </select>
        条
    </form>
    <%
        //该代码需要放置select标签后面，否则script中的代码会无效
        int pageSize = pages.getPageSize();
        if(pageSize==5){
            %>
                <script type="text/javascript">$("#sel").val("5");</script>
            <%
        }
        if(pageSize==10){
            %>
                <script type="text/javascript">$("#sel").val("10");</script>
            <%
        }
    %>

  </body>
</html>
